#include <iostream>
using namespace std;
int main()
{

	int n;
	while(cin>>n&&n!=0)
	{
		int ans=0;
		while(n>=3)
		{
			int t,y;
			t=n/3;
			y=n%3;
			ans=ans+t;
			n=t+y;
		}
		if(n==0||n==1) ;
		else ans++;
		cout<<ans<<endl;
	}
	return 0;
}
